﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

// Шаблон элемента пустой страницы задокументирован по адресу http://go.microsoft.com/fwlink/?LinkId=234238

namespace JarvisProject1
{
    /// <summary>
    /// Пустая страница, которую можно использовать саму по себе или для перехода внутри фрейма.
    /// </summary>
    public sealed partial class MessagePage : Page
    {
        int IndexSelectRubric = 0;
        MainPage obj = new MainPage();
        StoreDataMessage _storeData = null;

        public MessagePage()
        {
            this.InitializeComponent();   
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string[] parameter = (e.Parameter as string).Split(new char[] { '*' });
            IndexSelectRubric = Convert.ToInt32(parameter[0]);
            MessageNameText.Text = obj._object[0]._Rubrics[Convert.ToInt32(parameter[0])].Messsages[Convert.ToInt32(parameter[1])].Name_Message;
            RubricNameText.Text = "Рубрика: " + obj._object[0]._Rubrics[Convert.ToInt32(parameter[0])].RubrikName;
            Content_of_Message.Text = obj._object[0]._Rubrics[Convert.ToInt32(parameter[0])].Messsages[Convert.ToInt32(parameter[1])].Text_of_Message;

            _storeData = new StoreDataMessage(Convert.ToInt32(parameter[0]));
            List <GroupInfoList<object>> dataLetter = _storeData.GetGroupsByLetter();
            cvs2.Source = dataLetter;
            RubricaName.SelectedIndex = Convert.ToInt32(parameter[1]);

            Image_of_message.Source = new BitmapImage(new Uri("ms-appx://" + obj._object[0]._Rubrics[Convert.ToInt32(parameter[0])].Messsages[Convert.ToInt32(parameter[1])].ImageAdress));

            base.OnNavigatedTo(e);
        }


        private void GoToHome_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(MainPage));
        }

        private void Show_Rubrics_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(RubricPage));
            // Add_message.Visibility = Visibility.Collapsed;

        }

        private void Share_Click(object sender, RoutedEventArgs e)
        {
            //TO DO контракты ВК, Фейсбук, Твиттер и тп
        }

        private void Star_Messages_Click(object sender, RoutedEventArgs e)
        {
            // TO DO переход во вкладку избранные сообщения
        }
        private void Add_message_Click(object sender, RoutedEventArgs e)
        {

        }

        private void RubricaName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MessageNameText.Text = obj._object[0]._Rubrics[IndexSelectRubric].Messsages[RubricaName.SelectedIndex].Name_Message;
            RubricNameText.Text = "Рубрика: " + obj._object[0]._Rubrics[IndexSelectRubric].RubrikName;
            Content_of_Message.Text = obj._object[0]._Rubrics[IndexSelectRubric].Messsages[RubricaName.SelectedIndex].Text_of_Message;
            Image_of_message.Source = new BitmapImage(new Uri("ms-appx://" + obj._object[0]._Rubrics[IndexSelectRubric].Messsages[RubricaName.SelectedIndex].ImageAdress));
        }
    }
}
